package com.ih.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自己的拦截器并设置拦截
        //addPathPatterns 为拦截此请求路径的请求
        //excludePathPatterns()  不拦截此路径的请求
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**") //拦截所有
        .excludePathPatterns("/","/login","/index.html","/css/**","/fonts/**","/images/**","/js/**","favicon.ico");
    }

    //在配置类中.添加视图解析器

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //当你访问index.html 直接跳转index 登录页面
        registry.addViewController("index.html").setViewName("index");
    }
}
